﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Runtime.Serialization;

namespace ServeurRSS_1_0.Source.Model
{
    [DataContract]
    public class DataUser
    {
        [DataMember]
        public System.Guid id
        { get; set; }

        [DataMember]
        public string name
        { get; set; }

        [DataMember]
        public string email
        { get; set; }

        [DataMember]
        public string password
        { get; set; }

        [DataMember]
        public bool? connection_state
        { get; set; }

         [DataMember]
        public int? status
        { get; set; }

        [DataMember]
        public DateTime? date
        { get; set; }
    }

    public class UserModel
    {
        public DataUser getDataUser(User usr)
        {
            if (usr == null)
                return null;
            return new DataUser
            {
              id = usr.id,
              connection_state = usr.connection_state,
              date = usr.creation_date,
              email = usr.email,
              name = usr.login,
              password = usr.password,
              status = usr.statut
            };
        }

        public User getUserFromData(DataUser usr)
        {
            if (usr == null)
                return null;
            return new User
            {
                id = usr.id,
                connection_state = usr.connection_state,
                creation_date = usr.date,
                email = usr.email,
                login = usr.name,
                password = usr.password,
                statut = usr.status
            };
        }

        public List<User> getListFromData(List<DataUser> list)
        {
            if (list == null)
                return null;
            List<User> res = new List<User>();
            foreach (DataUser tmp in list)
                res.Add(getUserFromData(tmp));
            return res;

        }


        public List<DataUser> getListFromUser(List<User> list)
        {
            if (list == null)
                return null;
            List<DataUser> res = new List<DataUser>();
            foreach (User tmp in list)
                res.Add(getDataUser(tmp));
            return res;

        }
    }
}